package com.appos.service;

import com.appos.domain.WorkSheetGroupRelation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkSheetGroupRelationService {
    private static final Logger logger = LoggerFactory.getLogger(WorkSheetGroupRelationService.class);

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 保存对象
     * @param workSheetGroupRelation
     * @return
     */
    public int save(WorkSheetGroupRelation workSheetGroupRelation) {
        mongoTemplate.save(workSheetGroupRelation);
        return 1;
    }

    /***
     * 根据workSheetId查询
     * @param workSheetId
     * @return
     */
    public WorkSheetGroupRelation getWorkSheetGroupRelation(String workSheetId) {
        Query query = new Query(Criteria.where("workSheetId").is(workSheetId));
        return mongoTemplate.findOne(query, WorkSheetGroupRelation.class);
    }

    /***
     * 根据workSheetGroupUuid查询
     * @param workSheetGroupUuid
     * @return
     */
    public List<WorkSheetGroupRelation> getWorkSheetGroupRelationList(String workSheetGroupUuid) {
        Query query = new Query(Criteria.where("workSheetGroupUuid").is(workSheetGroupUuid));
        return mongoTemplate.find(query, WorkSheetGroupRelation.class);
    }

}
